package com.dk.shared.autoconfigure.swagger;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringDocConfig {

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(this.getApiInfo())
                .addSecurityItem(new SecurityRequirement().addList("token"))
                .components(
                        new Components()
                                .addSecuritySchemes("token",
                                        new SecurityScheme()
                                                .name("token")
                                                .type(SecurityScheme.Type.APIKEY)
                                                .in(SecurityScheme.In.HEADER)));
    }

    @Bean("defaultGroupApi")
    public GroupedOpenApi defaultGroupApi() {
        return GroupedOpenApi.builder().group("default")
                .pathsToMatch("/rest/**")
                .build();
    }

    private Info getApiInfo() {
        return new Info()
                .title("API文档")
                .description("Swagger3文档")
                .contact(new Contact().name("dk").url("https://www.***.cn").email("***@163.com"))
                .license(new License().name("Apache 2.0").url("https://www.***.cn"))
                .summary("API文档")
                .termsOfService("https://www.***.cn")
                .version("1.0");
    }

}
